<template>
	<view>
		<view v-for="(item,index) in Entity" :key="index">
			<view v-if="item.type=='select'" class="uni-list">
				<view class="uni-list-cell">
					<view class="uni-list-cell-left">
						{{item.label}}
					</view>
					<view class="uni-list-cell-db">
						<picker @change="bindPickerChange($event,index)" :value="item.index" :range="item.request"
							range-key="Text">
							<view class="uni-input">{{item.request[item.index].Text}}</view>
						</picker>
					</view>
				</view>
			</view>
			<view v-else class="uni-form-item uni-column">
				<view class="title"><text class="uni-form-item__title">{{item.label}}</text></view>
				<view class="uni-input-wrapper">
					<input class="uni-input" maxlength="20" :placeholder="msg+item.label" v-model="item.value" />
				</view>
				<!-- <label v-for="(value, name, index) in errormsgs" v-if="name=='Entity.SchoolCode'" class="color-red">
					{{value}}
				</label> -->
			</view>
		</view>

		<view class="uni-padding-wrap uni-common-mt">
			<view class="button-sp-area">
				<button type="default" @click="onFinish()">
					<slot name="Finish">提交</slot>
				</button>
			</view>
		</view>
		<view class="uni-padding-wrap uni-common-mt">
			<view class="button-sp-area">
				<button type="default" @click="onReset()">
					<slot name="Reset">重置</slot>
				</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				msg: "请输入"
			}
		},
		props: {
			// 检测类型 + 其他验证
			Entity: {
				type: Array,
				default: () => {
					return [];
				},
				required: true,
			},
			// Pagination: {
			// 	type: Object,
			// 	default: () => {
			// 		return {
			// 			// "Page": 1,
			// 			// "Limit": 20
			// 		}
			// 	},
			// 	required: true
			// }
			// PageIndex:{
			// 	type:Number,//String 、 Number 、 Boolean 、 Array 、 Object 、 Date 、 Function 、 Symbol ，任何自定义构造函数、或上述内容组成的数组
			// 	default:1,//为该 prop 指定一个默认值。如果该 prop 没有被传入，则换做用这个值。对象或数组的默认值必须从一个工厂函数返回。
			// },
			// Limit:{
			// 	type:Number,
			// 	default:10,
			// }
		},
		inject:['Pagination'],
		methods: {
			onFinish() {
				this.Pagination.Page=0;
			},
			bindPickerChange(e, index) { //下拉框
				this.Entity[index].index = e.detail.value;
				this.Entity[index].value = this.Entity[index].request[e.detail.value].Value;
			},
			onReset() {				
				var that = this;
				that.Entity.forEach(item => {
					if (item.type == null || item.type == "text") {
						item.value = "";
					}else if(item.type="select"){
						item.value =item.request[0].Value;
					}
				})
				console.log(JSON.stringify(that.Entity))
			}
		}
	}
</script>

<style>
</style>
